package com.alibaba.citrus.cr.common.log;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public enum OperateTypeEnum {
    CREATE(1, "新建"),
    EDIT(2, "编辑"),
    DELETE(3, "删除"),
    ENABLE(4, "启用"),
    DISABLE(5, "禁用"),
    CLOSE(6, "关闭");

    private Integer operateType;
    private String desc;

    OperateTypeEnum() {
    }

    OperateTypeEnum(Integer operateType, String desc) {
        this.operateType = operateType;
        this.desc = desc;
    }

    public Integer getOperateType() {
        return operateType;
    }

    public void setOperateType(Integer operateType) {
        this.operateType = operateType;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static OperateTypeEnum ofOperateType(Integer operateType) {
        if (null == operateType) {
            return null;
        }
        return Arrays.stream(values()).filter(operateTypeEnum -> operateTypeEnum.getOperateType().equals(operateType)).findAny().orElse(null);
    }

    public static OperateTypeEnum ofDesc(String desc) {
        if (StringUtils.isEmpty(desc)) {
            return null;
        }
        return Arrays.stream(values()).filter(operateTypeEnum -> operateTypeEnum.getDesc().equals(desc)).findAny().orElse(null);
    }

    public static Map<Integer, String> getMap() {
        Map<Integer, String> map = new HashMap<>();
        Arrays.stream(values()).forEach(operateTypeEnum -> {
            map.put(operateTypeEnum.getOperateType(), operateTypeEnum.getDesc());
        });
        return map;
    }
}
